<?php

// 这个文件是创建红包的

require_once 'AopSdk.php';

require_once 'function.inc.php';

require_once 'config.php';

$aop = new AopClient ();

$aop->gatewayUrl = $config['gatewayUrl'];

$aop->appId = $config['app_id'];

$aop->rsaPrivateKey = $config['merchant_private_key'];

$aop->alipayrsaPublicKey=$config['alipay_public_key'];

$aop->apiVersion = '1.0';

$aop->signType = $config['sign_type'];

$aop->postCharset='utf-8';

$aop->format='json';

$request = new AlipayMarketingCampaignCashCreateRequest ();

$request->setBizContent("{" .

    "\"coupon_name\":\"618福利红包\"," .

    "\"prize_type\":\"random\"," .

    "\"total_money\":\"1000.00\"," .

    "\"total_num\":\"5000\"," .

    "\"prize_msg\":\"送您一个红包\"," .

    "\"start_time\":\"NowTime\"," .

    "\"end_time\":\"2018-09-20 22:48:30\"," .

    "\"merchant_link\":\"".$config['merchant_link']."\"," . // 这里不要删掉用于支付成功后触发红包

    "\"send_freqency\":\"D1|L7\"" .

    "  }");

$result = $aop->execute ( $request);

writeLog ( "result: " . var_export ( $result, true ) );

$responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";

$resultCode = $result->$responseNode->code;

$arr=object_array($result->$responseNode);

echo json_encode($arr);

if(!empty($resultCode)&&$resultCode == 10000){

    printf("crowd_no:%s\r\norigin_crowd_no:%s\r\npay_url:%s",$arr["crowd_no"],$arr["origin_crowd_no"],urldecode($arr["pay_url"]));

}

